#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int f[2][5011],s[5011];
int n;
int a[5011];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
//	freopen("ex_after2.in","r",stdin);
//	freopen("after.out","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	f[0][0] = 1;
	s[0] = 1;
	int nw = 0,lst = 1;
	for(int i = 1;i <= n;i++)
	{
		swap(nw,lst);
		memset(f[nw],0,sizeof(f[nw]));
		for(int j = a[i] + 1;j <= n;j++)
			f[nw][j] = f[lst][j];
		for(int j = i - 1;~j;j--)
		{
			if(a[j + 1] > a[i])
				break;
			(f[nw][a[i]] += s[j]) %= mod;
		}
		for(int j = a[i];j <= n;j++)
			(s[i] += f[nw][j]) %= mod;
		for(int j = 1;j <= n;j++)
			cerr << f[nw][j] << " ";
		cerr << "\n";
	}
	cout << s[n];
	return 0;
}
